<?
require_once 'clogin.inc.php';
require_once 'admin_head.php';
?>

<? 
$model_name ='站点';
if ($_POST['action'] == 'edit'){
	$id = intval($_POST['id']);
	$sitename = $_POST['sitename'];
	$url = $_POST['url'];
	$info = $_POST['info'];
	$displayid = $_POST['displayid'];
	empty($displayid) ? $displayid = 0 : 0;
	$uid = $_SESSION["uid"];
	$update_time = time();
	
/*	echo $id;
	echo $sitename;
	echo $url;
	echo $info;
	echo $displayid;*/

	if (empty($id)) {
		$sql = "INSERT INTO {$tablepre}sites (sitename, url, info, displayid,uid,create_time,update_time) 
				VALUES('$sitename', '$url', '$info', $displayid,'$uid','$update_time','$update_time')";
		$edit = '添加';		
	}else{
		$sql = "UPDATE {$tablepre}sites SET sitename = '$sitename', url = '$url', info = '$info', displayid = $displayid,update_time=$update_time WHERE id = $id LIMIT 1";
	
		$edit = '修改';	
	} 
	mysql_query($sql); 	

	if ( mysql_affected_rows() == 1 ) {
		if(mysql_insert_id()) $id = mysql_insert_id();
		 showmsg("{$model_name}{$edit}成功！",'成功',"?id=$id",'返回');
		
	}else{
		 showmsg("{$model_name}{$edit}失败或没有修改！",'失败',"return",'返回');
	}
	
}
if ($_GET['id']) {
	$id = intval($_GET['id']);
	if ($_GET['action'] == 'del'){//删除
		$edit = '删除';	
		$sql = "DELETE FROM {$tablepre}sites WHERE id = $id LIMIT 1";
		mysql_query($sql);
		showmsg("{$model_name}{$edit}成功！",'成功',"../frmView_right.php",'返回');
		exit();
		
	}
	$sql = "SELECT * FROM {$tablepre}sites WHERE id = $id ";
	$result=mysql_query($sql); 
	$esites = mysql_fetch_array($result);
}
?>

<p>&nbsp;</p>

<div class="edit">
<div class="title"><?php 
if ($_GET['id']) {
	echo "编辑： $esites[sitename]  信息 [<a href=\"admin_site.php\">添加一个新的</a>]";
}else{
	echo "添加网站信息";
}
?></div>
<form id="form1" name="form1" method="post" action="">

<input name="action" type="hidden" value="edit" />
<input name="id" type="hidden" value="<? echo $esites['id'] ?>" />

	<br /><p><label>网站名称：</label> 
		
		  <input name="sitename" type="text" id="sitename" value="<? echo $esites['sitename'] ?>" size="80" style="width:80%" />
	</p>
		
		<p><label>网站URL：</label>
		
  <input name="url" type="text" id="url" value="<?   
  empty($esites['url']) ? $esites['url'] = 'http://' : 0; 
  echo $esites['url'];
  ?>" size="80" style="width:80%" />
  </p>
	
		<p><label>网站说明：</label>
        
         <textarea name="info" id="info" cols="50" rows="10"style="width:80%" ><? echo $esites['info'] ?></textarea> 
		 
        </p>
       
        <label>显示位置：</label> 
        <p>
          <input name="displayid" type="text" id="displayid" value="<? echo $esites['displayid'] ?>" size="5" />
    </p>
        <p>
         
          <input type="submit" name="Submit" value="提交" />
        
        </p>
</form></div>
<p>&nbsp;</p>
</body>
</html>